package com.shiyi.design.chain;

/**
 * @author wangzhanshuai
 * @date 2021/2/5 9:50 下午
 * @since 1.0
 */
public class UrlFilter implements MyFilter{

    @Override
    public void doFilter(MyRequest request, MyResponse response, MyFilterChain filterChain) {
        System.out.println("UrlFilter start!");
        String requestMsg = request.getMsg();
        if(requestMsg != null && !"".equals(requestMsg)) {
            requestMsg = requestMsg.replace("shiyi.com", "http://www.shiyi.com");
            request.setMsg(requestMsg);
        }
        filterChain.doFilter(request, response, filterChain);

        if(requestMsg != null && !"".equals(requestMsg)) {
            requestMsg = requestMsg.replace("http://www.shiyi.com", "shiyi.com");
            response.setMsg(requestMsg);
        }
        System.out.println("UrlFilter end!");
    }
}
